//
//  XHFirstTypeForeCell.m
//  umibus
//
//  Created by fengyn on 16/6/18.
//  Copyright © 2016年 lexingsoft. All rights reserved.
//

#import "XHFirstTypeForeCell.h"

@implementation XHFirstTypeForeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [self.ui_helpButton setRightImage];
    [self setdata];
}

- (void)setdata{
    NSArray *operatorNames=@[@"移动",@"联通",@"电信"];
    for(int i=0; i<3; i++){
        int row=i/3;
        int column=i%3;
        int screenWidth=[UIScreen mainScreen].bounds.size.width;
        int viewWidth=(screenWidth-40-10*(3-1))/3;
        UIButton *buttonView=[[UIButton alloc] initWithFrame:CGRectMake(column*viewWidth+column*10, row*35+row*10, viewWidth, 35)];
        buttonView.layer.masksToBounds=YES;
        buttonView.layer.cornerRadius=5;
        buttonView.layer.borderColor=[ColorManager colorWithMain].CGColor;
        buttonView.layer.borderWidth=1;
        [buttonView setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [buttonView setBackgroundColor:[ColorManager colorWithMain] forState:UIControlStateSelected];
        [buttonView setTitle:operatorNames[i] forState:UIControlStateNormal];
        [buttonView setTitleColor:[ColorManager colorWithMain] forState:UIControlStateNormal];
        [buttonView setTitleColor:[ColorManager whiteColor] forState:UIControlStateSelected];
        [buttonView.titleLabel setFont:[UIFont systemFontOfSize:17]];
        buttonView.tag=i;
        [buttonView addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.ui_borderView addSubview:buttonView];
    }
    self.ui_borderView.tag=99999;
}

- (void)setButtonSelectedWithTag:(NSInteger)tag{
    for (UIButton *buttonView in self.ui_borderView.subviews) {
        buttonView.selected=NO;
    }
    UIButton *buttonView=(UIButton *)[self.ui_borderView viewWithTag:tag];
    buttonView.selected=YES;
}

- (IBAction)helpButtonAction:(id)sender {
    if ([self.delegate respondsToSelector:@selector(helpButtonAction:)]) {
        [self.delegate helpButtonAction:sender];
    }
}

- (void)buttonAction:(UIButton *)sender{
    for (UIButton *buttonView in self.ui_borderView.subviews) {
        buttonView.selected=NO;
    }
    [sender setSelected:![sender isSelected]];
    if ([self.delegate respondsToSelector:@selector(operatorButtonAction:)]) {
        [self.delegate operatorButtonAction:sender];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
